import type { AddCartParams, CartItem } from '@/types/cart'
import { http } from '@/utils/http'

/**
 * 加入购物车
 * @param data body参数
 * @returns
 */
export const postMemberCartAPI = (data: AddCartParams) => {
  return http({
    method: 'POST',
    url: '/member/cart',
    data,
  })
}

/**
 * 获取购物车列表
 * @returns
 */
export const getMemberCartAPI = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}

/**
 * // /member/cart
 * @param ids SKUID集合
 * @returns
 */
export const deleteMemberCartAPI = (ids: string[]) => {
  return http({
    method: 'DELETE',
    url: '/member/cart',
    data: {
      ids,
    },
  })
}

/**
 * 修改购物车单品
 * @param skuId SKU ID
 * @param data Body 参数
 * @returns
 */
export const putMemberCartBySkuIdAPI = (
  skuId: string,
  data: {
    selected?: boolean
    count?: number
  },
) => {
  return http({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}

/**
 * 购物车全选/取消全选
 * @param selected 是否选中
 * @returns
 */
export const putMemberCartSelectedAPI = (selected: boolean) => {
  return http({
    method: 'PUT',
    url: '/member/cart/selected',
    data: {
      selected,
    },
  })
}
